import { forwardRef } from "react";
import { Button } from "antd";
import { AuthPermissionComponent } from "@/components/auth";
import PropTypes from "prop-types";

/**
 * 权限按钮
 *
 * @param {string} auth 权限标识
 * @param {object} resProps 按钮属性
 * @param {object} ref
 * @returns Component
 *
 *
 * [BUG]    Warning: findDOMNode is deprecated and will be removed in the next major release.
 * [DEBUG]  forwardRef：传递 ref 给子组件
 */
const AuthButton = forwardRef(({ auth, ...resProps }, ref) => {
  return (
    <AuthPermissionComponent auth={auth}>
      <Button {...resProps} ref={ref} />
    </AuthPermissionComponent>
  );
});

// 添加 displayName 属性
AuthButton.displayName = "AuthButton";

// 对 auth 进行类型检查
AuthButton.propTypes = {
  auth: PropTypes.string.isRequired, // 假设 auth 应该是一个字符串
};

export default AuthButton;
